#ifndef MESSAGETRANSLATOR_H
#define MESSAGETRANSLATOR_H

#include <QObject>
#include <QHash>

#include <QxPLMessage.h>
#include <QxPLUtils.h>
#include <ZxPLModuleStat.h>
#include <ZigbusMessage.h>
#include <ZModuleSettings.h>
#include <ZModuleSettingsDOM.h>

/**
   @brief The ModuleMessageHandler class
 */
class ModuleMessageHandler : public QObject
{
    Q_OBJECT
private:
    QList<ZxPLModuleStat*> modules;
    QString configFileName;

    void on_zigbus_message_init(const ZigbusMessage& message);
    void on_zigbus_init(const ZigbusMessage& message);


    void on_xPL_basic_control_cmd(const QxPLMessage &message);


    /* configuration management */
    ZModuleSettings findConfiguration(const QString& moduleName);
    bool registerConfiguration(const ZModuleSettings& settings);
    void sendConfigurationToModule(const ZModuleSettings& settings);
    ZigbusMessage create_config_numeric_output(const QString& moduleName, const QString& pinId, bool enable);
    ZigbusMessage create_config_meteo(const QString& moduleName, const QString& pinId, const QString &sensorType);
    ZigbusMessage create_config_heater(const QString& moduleName, const QString& alterp, const QString& alterm);
    ZigbusMessage create_config_pwm(const QString& moduleName, const QString& pinid, int value);
    void on_xPL_config_response_cmd(const QxPLMessage &message);
    void on_xPL_config_list_request(const QxPLMessage& message);
    void on_xPL_config_list_current(const QxPLMessage& message);


public:
    ModuleMessageHandler(QObject* parent = 0);
    ~ModuleMessageHandler();

    ZxPLModuleStat* registerModule(const QString& moduleName, bool hasToStart = true);
public slots:
    void processMessage(QxPLMessage message);
    void processMessage(ZigbusMessage message);
    void removeModule(QString moduleName);
    void ping(QString moduleName);
    void sendHeartbeat(QString moduleName, int hbeat);


signals:
    void zigbusMessageToSend(ZigbusMessage message);
    void xPLMessageToSend(QxPLMessage message);
};

#endif // MESSAGETRANSLATOR_H
